<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>简易计算器</title>
    <script language="javascript" type="text/javascript">
        var a;
        function t(){
            var num1=parseFloat(document.form1.textfield.value);
            var num2=parseFloat(document.form1.textfield2.value);
            var result;
            switch(a){
                case "1":result=num1+num2;document.form1.textfield3.value=result;a="0";break;
                case "2":result=num1-num2;document.form1.textfield3.value=result;a="0";break;
                case "3":result=num1*num2;document.form1.textfield3.value=result;a="0";break;
                case "4":result=num1/num2;document.form1.textfield3.value=result;a="0";break;
                default:document.form1.textfield3.value=("请问您要执行哪种运算？");break;
            }
        }
        function plus(){
            a="1";
        }
        function subtract(){
            a="2";
        }
        function multiply(){
            a="3";
        }
        function divide(){
            a="4";
        }
    </script>
</head>
<body>
<form  name="form1" method="post" action="">
    <label>
        <input type="text" name="textfield"  />
        <br />
        <input type="button"  value="+" onclick="plus()"/>
        <input type="button"  value="-" onclick="subtract()"/>
        <input type="button"  value="*" onclick="multiply()"/>
        <input type="button"  value="/" onclick="divide()"/>
        <br />
    </label>
    <label>
        <input type="text" name="textfield2"/>
        <br />
        <input type="button" name="button5"  value="=" onclick="t()"/>
        <br />
    </label>
    <label>
        <input type="text" name="textfield3" />
        <br />
    </label>
</form>
</body>
</html>